package com.comecrd.service.impl;

import com.comecrd.model.Like;
import com.comecrd.repository.LikeMapper;
import com.comecrd.service.LikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class LikeServiceImpl implements LikeService {
    
    @Autowired
    private LikeMapper likeMapper;
    
    @Override
    public Like findByUserIdAndCheckInId(Long userId, Long checkInId) {
        // 由于我们没有在MyBatis中返回Like对象，这里返回null
        // 实际项目中可以根据需要调整
        return null;
    }
    
    @Override
    public boolean isLiked(Long userId, Long checkInId) {
        Integer count = likeMapper.exists(userId, checkInId);
        return count != null && count > 0;
    }
    
    @Override
    @Transactional
    public Like save(Like like) {
        likeMapper.insert(like.getUserId(), like.getCheckInId());
        return like;
    }
    
    @Override
    @Transactional
    public void delete(Long userId, Long checkInId) {
        likeMapper.delete(userId, checkInId);
    }
    
    @Override
    public int countByCheckInId(Long checkInId) {
        Integer count = likeMapper.countByCheckInId(checkInId);
        return count != null ? count : 0;
    }
}